1.3. Running the Project 运行项目
项目将会被编译,并且进行单元测试
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.example.MyResourceTest
八月 30, 2014 9:35:06 上午 org.glassfish.grizzly.http.server.NetworkListener sta
rt
INFO: Started listener bound to [localhost:8080]
八月 30, 2014 9:35:06 上午 org.glassfish.grizzly.http.server.HttpServer start
INFO: [HttpServer] Started.
八月 30, 2014 9:35:07 上午 org.glassfish.grizzly.http.server.NetworkListener shu
tdownNow
INFO: Stopped listener bound to [localhost:8080]
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.485 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] BUILD SUCCESS
[INFO] Total time: 02:21 min
[INFO] Finished at: 2014-08-30T09:35:07+08:00
[INFO] Final Memory: 13M/31M
[INFO] ------------------------------------------------------------------------
上面可以看看到测试通过,下面我们用标准模式运行项目:
运行结果如下:
[INFO] Scanning for projects...
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethrea
ded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building simple-service 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> exec-maven-plugin:1.2.1:java (default-cli) @ simple-service >>>
[INFO]
[INFO] <<< exec-maven-plugin:1.2.1:java (default-cli) @ simple-service <<<
[INFO]
八月 30, 2014 9:36:57 上午 org.glassfish.grizzly.http.server.NetworkListener sta
rt
八月 30, 2014 9:36:57 上午 org.glassfish.grizzly.http.server.HttpServer start
INFO: [HttpServer] Started.
Jersey app started with WADL available at http://localhost:8080/myapp/applicatio
n.wadl
Hit enter to stop it...
更多 WADL的内容,请查考
接下来试下与部署在 /myresource
下面的资源的交互。将资源的URL输入浏览器,或者在控制台用curl
命令执行(译者注:如果没有安装curl,请参考):
用-i
命令获取所有回应的头文件信息:
$ curl -i http://localhost:8080/myapp/myresource
HTTP/1.1 200 OK
Content-Type: text/plain
Date: Sat, 30 Aug 2014 02:23:25 GMT
Content-Length: 7
Got it!
注意到Content-Type: text/plain
是在 MyResource 类中用@Produces
注解的。
如果想看到更多返回信息,可以变换不同的 curl 命令参数。举例: